package com.jozen.smart_toilet_system.ui;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.bumptech.glide.signature.ObjectKey;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.PlayerView;
import com.jozen.modelbase.netwoek.Common;
import com.jozen.modelbase.netwoek.base.BaseFragment;
import com.jozen.modelbase.netwoek.base.BaseReqModel;
import com.jozen.modelbase.netwoek.base.ModuleBaseApplication;
import com.jozen.modelbase.netwoek.bean.CityConfModel;
import com.jozen.modelbase.netwoek.bean.HomeModel;
import com.jozen.modelbase.netwoek.bean.SmartToiletInterfaceConfModel;
import com.jozen.modelbase.netwoek.bean.TitleModel;
import com.jozen.modelbase.netwoek.bean.WeatherNowModel;
import com.jozen.modelbase.netwoek.util.CrossFadeDrawable;
import com.jozen.modelbase.netwoek.util.DateUtil;
import com.jozen.modelbase.netwoek.util.GlideUtil;
import com.jozen.modelbase.netwoek.util.JsonUtil;
import com.jozen.smart_toilet_system.R;
import com.jozen.smart_toilet_system.adapter.BannerAdapter;
import com.jozen.smart_toilet_system.bean.BannerData;
import com.jozen.smart_toilet_system.mvp.HomeContract;
import com.jozen.smart_toilet_system.mvp.HomePresenter;
import com.jozen.smart_toilet_system.tagView.ToiletRoomTagShowLayout;
import com.jozen.smart_toilet_system.ui.common_toile_room_tag_view.RecyclerViewAdapter;
import com.jozen.smart_toilet_system.ui.common_toile_room_tag_view.RecyclerViewAdapter2;
import com.ruffian.library.widget.RLinearLayout;
import com.xiaweizi.marquee.MarqueeTextView;
import com.zhpan.bannerview.BannerViewPager;
import com.zhpan.indicator.enums.IndicatorSlideMode;
import com.zhpan.indicator.enums.IndicatorStyle;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HomeFragment extends BaseFragment<HomeContract.Presenter> implements HomeContract.View {
    @BindView(R.id.tv_day)
    TextView tv_day;
    @BindView(R.id.TagLineGroup)
    ConstraintLayout TagLineGroup;
    @BindView(R.id.tvTagline)
    MarqueeTextView tvTagline;
    @BindView(R.id.tv_city)
    TextView tv_city;
    @BindView(R.id.tv_weather_temp)
    TextView tv_weather_temp;
    @BindView(R.id.tv_weather_des)
    TextView tv_weather_des;
    @BindView(R.id.iv_weather_state)
    ImageView iv_weather;
    @BindView(R.id.ivTitleLogo)
    ImageView ivTitleLogo;
    @BindView(R.id.rv_des)
    RecyclerView rv_des;
    @BindView(R.id.rv_man_list)
    RecyclerView rv_man_list;
    @BindView(R.id.rv_woman_list)
    RecyclerView rv_woman_list;
    @BindView(R.id.rv_third_list)
    RecyclerView rv_third_list;
    @BindView(R.id.numRv)
    RecyclerView numRv;
    @BindView(R.id.tv_current_passenger_flow_val)
    TextView tv_current_passenger_flow_val;//今日客流量
    @BindView(R.id.tv_total_passenger_flow_val)
    TextView tv_total_passenger_flow_val;//总客流量
    //组态相关
    @BindView(R.id.iv_bg_img)
    ImageView iv_bg_img;
    @BindView(R.id.zt_show_tag_layout)
    ToiletRoomTagShowLayout zt_show_tag_layout;
    @BindView(R.id.iv_bg_img2)
    ImageView iv_bg_img2;
    @BindView(R.id.zt_show_tag_layout2)
    ToiletRoomTagShowLayout zt_show_tag_layout2;

    @BindView(R.id.llManGroup)
    LinearLayout llManGroup;

    @BindView(R.id.llSpareUrinal)
    LinearLayout llSpareUrinal;

    @BindView(R.id.tvMan)
    TextView tvMan;

    @BindView(R.id.tvManTotal)
    TextView tvManTotal;

    @BindView(R.id.SpareUrinal)
    TextView SpareUrinal;

    @BindView(R.id.SpareUrinalSum)
    TextView SpareUrinalSum;

    @BindView(R.id.llFemaleGroup)
    LinearLayout llFemaleGroup;

    @BindView(R.id.tvFemale)
    TextView tvFemale;

    @BindView(R.id.tvFemaleTotal)
    TextView tvFemaleTotal;

    @BindView(R.id.llBabyGroup)
    LinearLayout llBabyGroup;

    @BindView(R.id.tvBaby)
    TextView tvBaby;

    @BindView(R.id.tvBabyTotal)
    TextView tvBabyTotal;

    @BindView(R.id.llBabyGroup2)
    LinearLayout llBabyGroup2;

    @BindView(R.id.tvBaby2)
    TextView tvBaby2;

    @BindView(R.id.tvBabyTotal2)
    TextView tvBabyTotal2;

    @BindView(R.id.llThirdGroup)
    LinearLayout llThirdGroup;

    @BindView(R.id.tvThird)
    TextView tvThird;

    @BindView(R.id.tvThirdTotal)
    TextView tvThirdTotal;

    @BindView(R.id.llThirdGroup2)
    LinearLayout llThirdGroup2;

    @BindView(R.id.tvThird2)
    TextView tvThird2;

    @BindView(R.id.tvThirdTotal2)
    TextView tvThirdTotal2;


    @BindView(R.id.biaoGroup)
    RLinearLayout biaoGroup;

    @BindView(R.id.llDidanbiaoGroup)
    LinearLayout llDidanbiaoGroup;

    @BindView(R.id.tvDianbiao)
    TextView tvDianbiao;

    @BindView(R.id.llWaterGroup)
    LinearLayout llWaterGroup;

    @BindView(R.id.llTimeGroup)
    LinearLayout llTimeGroup;

    @BindView(R.id.timeGroup)
    LinearLayout timeGroup;

    @BindView(R.id.llSingleTimeGroup)
    LinearLayout llSingleTimeGroup;

    @BindView(R.id.llEnvEnable)
    RLinearLayout llEnvEnable;
    @BindView(R.id.llMaleEnvEnable)
    LinearLayout llMaleEnvEnable;

    @BindView(R.id.llFemaleEnvEnable)
    LinearLayout llFemaleEnvEnable;

    @BindView(R.id.llFamilyEnvEnable)
    LinearLayout llFamilyEnvEnable;

    @BindView(R.id.group2)
    LinearLayout group2;


    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.tvWater)
    TextView tvWater;

    @BindView(R.id.rlRightGroup)
    RLinearLayout rlRightGroup;


    //图片广告轮播
    @BindView(R.id.rl_adv_layout)
    RelativeLayout rl_adv_layout;
    @BindView(R.id.bannerViewPager)
    BannerViewPager bannerViewPager;
    //    @BindView(R.id.video_view)
//    FullScreenVideoView v_video;
    @BindView(R.id.player_view)
    PlayerView mPlayerView;
    private SimpleExoPlayer mPlayer;

    private BannerAdapter bannerAdapter;
    private List<BannerData> bannerDataList = new ArrayList<>();
    private List<HomeModel.EnvDataListDto> devTypeList = new ArrayList<>();
    private List<HomeModel.ListDTO> manList = new ArrayList<>();
    private List<HomeModel.ListDTO> womanList = new ArrayList<>();

    private List<HomeModel.ListDTO> thirdList = new ArrayList<>();
    private DevTypeAdapter devTypeAdapter;
    private ManAdapter manAdapter, womanAdapter, thirdAdapter;
    private String videoUrl = "";//视频广告链接
    private long advUpdateTime = -1;//广告轮播图更新时间
    private CityConfModel cityConfModel;
    private String mTagline = "";


    @Override
    protected HomePresenter initPresenter() {
        return new HomePresenter();
    }

    @Override
    protected int getFragmentLayoutID() {
        return R.layout.fragment_smart_toilet_home;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mPlayer = new SimpleExoPlayer.Builder(mContext).build();
        initRv();
        showMainTopData();
        initBannerVp();
//        getPermissionX();
        showTypeList();
        getApi();
    }

    private void getApi() {
        getCityAndKeyConf();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                getSmartToiletHomePage();
                getSmartToiletNameConf();
                getSmartToiletInterfaceConf();
            }
        }, 2000, 5000);

    }


    private void playVideo() {
        try {

            MediaItem mediaItem = MediaItem.fromUri(videoUrl);
            mPlayer.setMediaItem(mediaItem);
            mPlayerView.setControllerAutoShow(false);
            mPlayerView.setPlayer(mPlayer);
            mPlayer.prepare();
            mPlayer.play();

            mPlayerView.setKeepScreenOn(true);
            mPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH);

//            if (TextUtils.isEmpty(videoUrl)) return;
//            String uri = "https://v-cdn.zjol.com.cn/276982.mp4";
////            String uri = "android.resource://" + mActivity.getPackageName() + "/" + R.raw.my_video_file;
//            v_video.setVideoPath(videoUrl);
//
//
////            v_video.setOnPreparedListener(mp -> {
////                mp.setLooping(true);
////                mp.start();
////            });
//
//            v_video.setOnCompletionListener(mp -> {
//                playVideo();
////                v_video.seekTo(0);
////                v_video.start();
//            });
//
//
//            v_video.setOnErrorListener((mp, what, extra) -> {
//                String errorMessage = "";
//                switch (what) {
//                    case MediaPlayer.MEDIA_ERROR_UNKNOWN:
//                        errorMessage = "未知错误";
//                        break;
//                    case MediaPlayer.MEDIA_ERROR_IO:
//                        errorMessage = "I/O 错误";
//                        break;
//                    case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
//                        errorMessage = "不支持的媒体格式";
//                        break;
//                    case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
//                        errorMessage = "超时错误";
//                        break;
//                    default:
//                        errorMessage = "播放错误";
//                        break;
//                }
//                MyToastUtil.show(errorMessage);
//                return true;// 返回 true 表示错误已处理
//            });
//            v_video.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    private void initBannerVp() {
        bannerViewPager.setAdapter(new BannerAdapter()).registerLifecycleObserver(getLifecycle()).setIndicatorStyle(IndicatorStyle.DASH).setIndicatorVisibility(View.VISIBLE).setIndicatorMargin(0, 0, 0, 10).setIndicatorSlideMode(IndicatorSlideMode.SMOOTH).setIndicatorSliderColor(ContextCompat.getColor(mContext, R.color.color_333333), ContextCompat.getColor(mContext, R.color.color_0A8FFF)).create();
    }

    private void getCityAndKeyConf() {
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (mPresenter == null || mView == null) return;
                BaseReqModel baseReqModel = new BaseReqModel();
                baseReqModel.setFunctionName("getCityAndKeyConf");
                baseReqModel.setAuthorization("");
                baseReqModel.setParameters(new Object());
                mPresenter.getCityAndKeyConf(baseReqModel);
            }
        }, 10, Common.DELAY_MILLIS);
    }

    //获取首页信息
    private void getSmartToiletHomePage() {
        if (mPresenter == null || mView == null) return;
        BaseReqModel baseReqModel = new BaseReqModel();
        baseReqModel.setFunctionName("SmartToiletHomePage");
        baseReqModel.setAuthorization("");
        baseReqModel.setParameters(new Object());
        mPresenter.getSmartToiletHomePage(baseReqModel);
    }

    //获取厕所名称
    private void getSmartToiletNameConf() {
        if (mPresenter == null || mView == null) return;
        BaseReqModel baseReqModel = new BaseReqModel();
        baseReqModel.setFunctionName("getSmartToiletNameConf");
        baseReqModel.setAuthorization("");
        baseReqModel.setParameters(new Object());
        mPresenter.getSmartToiletNameConf(baseReqModel);
    }

    //获取厕组态配置
    private void getSmartToiletInterfaceConf() {
        if (mPresenter == null || mView == null) return;
        BaseReqModel baseReqModel = new BaseReqModel();
        baseReqModel.setFunctionName("getSmartToiletInterfaceConf");
        baseReqModel.setAuthorization("");
        baseReqModel.setParameters(new Object());
        mPresenter.getSmartToiletInterfaceConf(baseReqModel);
    }


    private void initRv() {
        rv_des.setLayoutManager(new LinearLayoutManager(mContext));
        rv_man_list.setLayoutManager(new LinearLayoutManager(mContext));
        rv_woman_list.setLayoutManager(new LinearLayoutManager(mContext));
        rv_des.setNestedScrollingEnabled(false);
        rv_man_list.setNestedScrollingEnabled(false);
        rv_woman_list.setNestedScrollingEnabled(false);
        rv_third_list.setNestedScrollingEnabled(false);
    }


    private void showTypeList() {
        if (devTypeAdapter == null) {
            devTypeAdapter = new DevTypeAdapter(R.layout.item_dev_type_list);
            rv_des.setAdapter(devTypeAdapter);
        }
        devTypeAdapter.setNewData(devTypeList);
    }


    private void showManList() {
        if (manAdapter == null) {
            manAdapter = new ManAdapter(manList);
            rv_man_list.setAdapter(manAdapter);
        }
        manAdapter.setNewData(manList);

    }


    private void showWomanList() {
        if (womanAdapter == null) {
            womanAdapter = new ManAdapter(womanList);
            rv_woman_list.setAdapter(womanAdapter);
        }
        womanAdapter.setNewData(womanList);

    }

    private void showThirdList() {
        if (thirdAdapter == null) {
            thirdAdapter = new ManAdapter(womanList);
            rv_third_list.setAdapter(thirdAdapter);
        }
        thirdAdapter.setNewData(womanList);

    }


//    private void getPermissionX() {
//        try {
//            PermissionX.init(this).
//                    permissions(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CHANGE_WIFI_STATE)
//                    .onExplainRequestReason((explainScope, list) -> {//被用户拒绝的权限
//
//                    })
//                    .request((allGranted, list, list1) -> {
//                        if (allGranted) {//已授权
//                            Common.CITY_NAME = SpMkvUtils.decodeString(Common.SP_CITY_KEY);
//                            if (TextUtils.isEmpty(Common.CITY_NAME)) {//已经定位获取过当前是什么城市，不需要每次都弹出
//                                privacyCompliance();
//                            } else {
//                                String id = SpMkvUtils.decodeString(Common.SP_CITY_ID_KEY);
////                                getWeather(id);
//                            }
//                        } else {//申请权限被拒绝
//                            Toast.makeText(mActivity, "请授权，才可获取相关信息！", Toast.LENGTH_SHORT).show();
//                        }
//                    });
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }


    //自动刷新顶部日期时间
    private void showMainTopData() {
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                mActivity.runOnUiThread(() -> {
                    try {
                        Date date = new Date();
                        String time = DateUtil.getDate(date, "yyyy/MM/dd");
                        String week = DateUtil.getWeek(date);
                        tv_day.setText(time + "  " + DateUtil.getDate(date, "HH") + ":" + DateUtil.getDate(date, "mm") + ":" + DateUtil.getDate(date, "ss"));
                        tvTime.setText(time + "  " + DateUtil.getDate(date, "HH") + ":" + DateUtil.getDate(date, "mm") + ":" + DateUtil.getDate(date, "ss"));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
            }
        }, 10, 1000);
    }


//    private void getGeoCityLookup() {
//        QWeather.getGeoCityLookup(mContext, Common.CITY_NAME, new QWeather.OnResultGeoListener() {
//            @Override
//            public void onError(Throwable throwable) {
//
//            }
//
//            @Override
//            public void onSuccess(GeoBean geoBean) {
//                try {
//                    if (Code.OK == geoBean.getCode()) {
//                        GeoBean.LocationBean locationBean = geoBean.getLocationBean().get(0);
//                        if (locationBean != null) {
//                            String id = "";
//                            if (!TextUtils.isEmpty(locationBean.getId())) {
//                                id = locationBean.getId();
//                                SpMkvUtils.encode(Common.SP_CITY_ID_KEY, id);
//                            }
////                            getWeather(id);
//                        }
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//
//    }

    //获取天气信息
    private void getWeatherInfo() {
        try {
            OkHttpClient okHttpClient = new OkHttpClient();
            Request request = new Request.Builder().url("https://devapi.qweather.com/v7/weather/now?location=" + cityConfModel.getCityId() + "&key=" + cityConfModel.getKey()).build();
            Call call = okHttpClient.newCall(request);
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    Log.d("IOException", e.toString());
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    String jsonInfo = response.body().string();
                    if (!TextUtils.isEmpty(jsonInfo)) {
                        WeatherNowModel weatherBean = JsonUtil.getBeanFromJson(jsonInfo, WeatherNowModel.class);
                        if (weatherBean != null && weatherBean.getNow() != null) {
                            mActivity.runOnUiThread(() -> {
                                try {
                                    String weather = weatherBean.getNow().getText();
                                    if (!TextUtils.isEmpty(weather)) {
                                        if (weather.contains("雨") || weather.contains("冰")) {
                                            iv_weather.setImageResource(R.drawable.ic_yutian);
                                        } else if (weather.contains("阴") || weather.contains("云")) {
                                            iv_weather.setImageResource(R.drawable.ic_duoyun);
                                        } else if (weather.contains("晴")) {
                                            iv_weather.setImageResource(R.drawable.ic_qingtian);
                                        } else if (weather.contains("雪")) {
                                            iv_weather.setImageResource(R.drawable.ic_xue_tian);
                                        } else {
                                            iv_weather.setImageResource(R.drawable.ic_duoyun);
                                        }
                                    }
                                    tv_city.setText(cityConfModel.getCityName() + "");
                                    tv_weather_temp.setText(weatherBean.getNow().getTemp() + "°C");
                                    tv_weather_des.setText(weather + "");
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            });
                        }
                    }
                }
            });
        } catch (Exception e) {
            Log.d("IOException", e.toString());
        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    private synchronized void getAdvPhotoList(List<HomeModel.PhotoBean> photoBeanList) {
        if (bannerDataList != null) {
            bannerDataList.clear();
            for (int i = 0; i < photoBeanList.size(); i++) {
                bannerDataList.add(new BannerData(photoBeanList.get(i).getPhotoPath()));
            }
            if (bannerViewPager != null) {
                bannerViewPager.refreshData(bannerDataList);
            }
        }
    }


    private static final int AUTO_SCROLL_DELAY = 5000; // 自动轮播延迟时间
    private RecyclerViewAdapter2 adapter;
    private Handler handler = new Handler();
    private int currentIndex = 0;

//    private Runnable autoScrollRunnable = new Runnable() {
//        @Override
//        public void run() {
//            if (currentIndex < adapter.getItemCount() - 1) {
//                currentIndex++;
//                smoothScrollToPosition(currentIndex);
//            } else {
//                currentIndex = 0;
//                smoothScrollToPosition(currentIndex);
//            }
//            handler.postDelayed(this, AUTO_SCROLL_DELAY);
//        }
//    };

//    private void smoothScrollToPosition(int position) {
//        if (layoutManager == null || numRv == null) {
//            return;
//        }
//
//        RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(requireActivity()) {
//            @Override
//            protected int getHorizontalSnapPreference() {
//                return SNAP_TO_START;
//            }
//
//            @Override
//            protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
//                // 调整速度值以获得更流畅的滚动效果
//                return 0.5f / displayMetrics.densityDpi;
//            }
//        };
//
//        smoothScroller.setTargetPosition(position);
//        layoutManager.startSmoothScroll(smoothScroller);
//    }

//    @Override
//    public void onDestroy() {
//        super.onDestroy();
//        handler.removeCallbacks(autoScrollRunnable);
//    }


    @SuppressLint("SetTextI18n")
    @Override
    public void getSmartToiletHomePageResult(HomeModel model) {
        try {
            if (model != null) {

                if (!TextUtils.isEmpty(model.getCityId())) {
                    if (cityConfModel != null) {
                        if (!TextUtils.isEmpty(cityConfModel.getCityId()) && !cityConfModel.getCityId().equals(model.getCityId())) {
                            getCityAndKeyConf();
                        }
                    } else {
                        getCityAndKeyConf();
                    }
                }
                //Tagline 字段值：（字符串类型，字符串为空时不展示标语）
                if (TextUtils.isEmpty(model.getTagline())) {
                    TagLineGroup.setVisibility(View.GONE);
                } else {
                    if (TextUtils.isEmpty(mTagline) || !mTagline.equals(model.getTagline())) {
                        TagLineGroup.setVisibility(View.VISIBLE);
                        tvTagline.setText(model.getTagline());
                        tvTagline.startScroll();
                        tvTagline.invalidate();
                        mTagline = model.getTagline();
                    }
                }


                tv_current_passenger_flow_val.setText(model.getTodayHumanSum() + "");
                tv_total_passenger_flow_val.setText(model.getTotalHumanSum() + "");


                //男厕
                llManGroup.setVisibility(model.getMaleSpareToilet() >= 0 || model.getSpareUrinal() >= 0 ? View.VISIBLE : View.GONE);
                tvMan.setText(model.getMaleSpareToilet() + "");
                tvManTotal.setText(model.getMaleToiletSu() + "");
                llSpareUrinal.setVisibility(model.getSpareUrinal() >= 0 ? View.VISIBLE : View.GONE);
                SpareUrinal.setText(model.getSpareUrinal() + "");
                SpareUrinalSum.setText(model.getUrinalSu() + "");

                //女厕
                llFemaleGroup.setVisibility(model.getFemaleSpareToilet() >= 0 ? View.VISIBLE : View.GONE);
                tvFemale.setText(model.getFemaleSpareToilet() + "");
                tvFemaleTotal.setText(model.getFemaleToiletSu() + "");


                //水表
                llWaterGroup.setVisibility(model.isShowWaterMeterFlag() ? View.VISIBLE : View.GONE);
                tvWater.setText(model.getWaterMeterData() + "");
                //电表
                llDidanbiaoGroup.setVisibility(model.isShowEnergyMeterFlag() ? View.VISIBLE : View.GONE);
                tvDianbiao.setText(model.getEnergyMeterData() + "");

                if (!model.isShowEnergyMeterFlag() && !model.isShowWaterMeterFlag()) {
                    biaoGroup.setVisibility(View.GONE);
                } else {
                    biaoGroup.setVisibility(View.VISIBLE);
                }

                //时钟样式 字段值：（ 0：不显示 1：单时钟 2：时钟+天气）
                if (model.getToiletTimeShowType() == 0) {
                    timeGroup.setVisibility(View.INVISIBLE);
                } else if (model.getToiletTimeShowType() == 1) {
                    timeGroup.setVisibility(View.VISIBLE);
                    llTimeGroup.setVisibility(View.GONE);
                    iv_weather.setVisibility(View.GONE);
                    llSingleTimeGroup.setVisibility(View.VISIBLE);
                } else if (model.getToiletTimeShowType() == 2) {
                    timeGroup.setVisibility(View.VISIBLE);
                    llTimeGroup.setVisibility(View.VISIBLE);
                    iv_weather.setVisibility(View.VISIBLE);
                    llSingleTimeGroup.setVisibility(View.GONE);
                }

                switch (model.getAdvertiseType()) {
                    case 0://无
//                        videoUrl = "";
                        if (TextUtils.isEmpty(model.getTagline()) && TextUtils.isEmpty(model.getKey()) && !model.isMaleEnvEnable() && !model.isFamilyEnvEnable() && !model.isBabyCareEnvEnable()) {
                            rlRightGroup.setVisibility(View.GONE); //右侧视图隐藏、厕所示意图居中
                            iv_bg_img2.setVisibility(View.VISIBLE);
                            zt_show_tag_layout2.setVisibility(View.VISIBLE);
                            iv_bg_img.setVisibility(View.GONE);
                            zt_show_tag_layout.setVisibility(View.GONE);

                            group2.setVisibility(View.GONE);


                            //第三卫
                            llThirdGroup.setVisibility(model.getFamilyToilet() >= 0 ? View.VISIBLE : View.GONE);
                            tvThird.setText(model.getFamilyToilet() + "");
                            tvThirdTotal.setText(model.getFamilyToiletSu() + "");

                            //母婴室
                            llBabyGroup.setVisibility(model.getBabyCareToilet() >= 0 ? View.VISIBLE : View.GONE);
                            tvBaby.setText(model.getBabyCareToilet() + "");
                            tvBabyTotal.setText(model.getBabyCareToiletSu() + "");
                        } else {
                            group2.setVisibility(View.VISIBLE);
                            llThirdGroup.setVisibility(View.GONE);
                            llBabyGroup.setVisibility(View.GONE);

                            //第三卫
                            llThirdGroup2.setVisibility(model.getFamilyToilet() >= 0 ? View.VISIBLE : View.GONE);
                            tvThird2.setText(model.getFamilyToilet() + "");
                            tvThirdTotal2.setText(model.getFamilyToiletSu() + "");

                            //母婴室
                            llBabyGroup2.setVisibility(model.getBabyCareToilet() >= 0 ? View.VISIBLE : View.GONE);
                            tvBaby2.setText(model.getBabyCareToilet() + "");
                            tvBabyTotal2.setText(model.getBabyCareToiletSu() + "");

                            rlRightGroup.setVisibility(View.VISIBLE);
                            iv_bg_img2.setVisibility(View.GONE);
                            zt_show_tag_layout2.setVisibility(View.GONE);
                            iv_bg_img.setVisibility(View.VISIBLE);
                            zt_show_tag_layout.setVisibility(View.VISIBLE);


                        }
                        rl_adv_layout.setVisibility(View.GONE);
//                        mPlayerView.setVisibility(View.GONE);
//                        mPlayer.pause();
//                        //默认广告图
//                        String imageUrl1 = "android.resource://" + mActivity.getPackageName() + "/" + R.drawable.ic_advertisement_def;
//                        if (bannerDataList.size() > 0 && bannerDataList.get(0).getImgUrl().equals(imageUrl1)) return;
//
//                        bannerDataList.clear();
//                        if (bannerDataList != null && bannerDataList.size() == 0) {
//                            bannerDataList.add(new BannerData(imageUrl1));
//                            bannerViewPager.refreshData(bannerDataList);
//                        }
                        break;
                    case 1://视频
                        rl_adv_layout.setVisibility(View.VISIBLE);
                        bannerDataList.clear();
                        bannerViewPager.setVisibility(View.GONE);
                        mPlayerView.setVisibility(View.VISIBLE);
                        if (!TextUtils.isEmpty(model.getVideoPath())) {
                            videoUrl = model.getVideoPath();
                            if (!mPlayer.isPlaying()) {
                                playVideo();
                            }
                        } else {
                            videoUrl = "";
                        }
                        group2.setVisibility(View.VISIBLE);
                        llThirdGroup.setVisibility(View.GONE);
                        llBabyGroup.setVisibility(View.GONE);
                        //第三卫
                        llThirdGroup2.setVisibility(model.getFamilyToilet() >= 0 ? View.VISIBLE : View.GONE);
                        tvThird2.setText(model.getFamilyToilet() + "");
                        tvThirdTotal2.setText(model.getFamilyToiletSu() + "");

                        //母婴室
                        llBabyGroup2.setVisibility(model.getBabyCareToilet() >= 0 ? View.VISIBLE : View.GONE);
                        tvBaby2.setText(model.getBabyCareToilet() + "");
                        tvBabyTotal2.setText(model.getBabyCareToiletSu() + "");
                        break;
                    case 2://图片轮播
                        rl_adv_layout.setVisibility(View.VISIBLE);
                        videoUrl = "";
                        //只有更改过图片之后才进行重新设置轮播图
                        if (model.getUpdateTime() > advUpdateTime) {
                            advUpdateTime = model.getUpdateTime();

                            bannerViewPager.setVisibility(View.VISIBLE);
                            mPlayerView.setVisibility(View.GONE);
                            mPlayer.pause();
                            bannerDataList.clear();
                            if (model.getPhotoList() != null && model.getPhotoList().size() > 0) {
                                getAdvPhotoList(model.getPhotoList());
                            } else {
                                bannerViewPager.setVisibility(View.GONE);
//                                String imageUrl2 = "android.resource://" + mActivity.getPackageName() + "/" + R.drawable.ic_advertisement_def;
//                                if (bannerDataList != null && bannerDataList.size() == 0) {
//                                    bannerDataList.add(new BannerData(imageUrl2));
//                                    bannerViewPager.refreshData(bannerDataList);
//                                }
                            }
                        }
                        group2.setVisibility(View.VISIBLE);
                        llThirdGroup.setVisibility(View.GONE);
                        llBabyGroup.setVisibility(View.GONE);
                        //第三卫
                        llThirdGroup2.setVisibility(model.getFamilyToilet() >= 0 ? View.VISIBLE : View.GONE);
                        tvThird2.setText(model.getFamilyToilet() + "");
                        tvThirdTotal2.setText(model.getFamilyToiletSu() + "");

                        //母婴室
                        llBabyGroup2.setVisibility(model.getBabyCareToilet() >= 0 ? View.VISIBLE : View.GONE);
                        tvBaby2.setText(model.getBabyCareToilet() + "");
                        tvBabyTotal2.setText(model.getBabyCareToiletSu() + "");
                        break;
                }


                //客流量
                ArrayList<HomeModel.ListKeliu> dtos = new ArrayList<>();
                //1 总日 2 男厕 3 女厕 4 第三卫
                if (model.isTotalHumanEnable()) { //总人流量
                    HomeModel.ListKeliu item = new HomeModel.ListKeliu();
                    item.setType(1);
                    item.setTotalNu(model.getTotalHumanSu());
                    item.setNu(model.getTodayHumanSum());
                    dtos.add(item);
                }
                if (model.isMaleHumanEnable()) { //男厕
                    HomeModel.ListKeliu item = new HomeModel.ListKeliu();
                    item.setType(2);
                    item.setTotalNu(model.getMaleTotalHumanSu());
                    item.setNu(model.getMaleTodayHumanSu());
                    dtos.add(item);
                }
                if (model.isFemaleHumanEnable()) { //女厕
                    HomeModel.ListKeliu item = new HomeModel.ListKeliu();
                    item.setType(3);
                    item.setTotalNu(model.getFemaleTotalHumanSu());
                    item.setNu(model.getFemaleTodayHumanSu());
                    dtos.add(item);
                }
                if (model.isFamilyHumanEnable()) { //第三卫
                    HomeModel.ListKeliu item = new HomeModel.ListKeliu();
                    item.setType(4);
                    item.setTotalNu(model.getFamilyTotalHumanSu());
                    item.setNu(model.getFamilyTodayHumanSu());
                    dtos.add(item);
                }
                adapter = new RecyclerViewAdapter2(dtos);
                LinearLayoutManager layoutManager = new LinearLayoutManager(requireActivity(), LinearLayoutManager.HORIZONTAL, false);
                numRv.setLayoutManager(layoutManager);
                numRv.setAdapter(adapter);


                if (model.getEnvDataList() != null && model.getEnvDataList().size() > 0) {//设备列表
                    devTypeList.clear();
                    devTypeList.addAll(model.getEnvDataList());
                    showTypeList();
                } else {
                    devTypeList.clear();
                    showTypeList();
                }

                if (model.getFemaleList() != null && model.getFemaleList().size() > 0) {//女厕
                    womanList.clear();
                    womanList.addAll(model.getFemaleList());
                    showWomanList();
                } else {
                    womanList.clear();
                    showWomanList();
                }

                if (model.getMaleList() != null && model.getMaleList().size() > 0) {//男厕
                    manList.clear();
                    manList.addAll(model.getMaleList());
                    showManList();
                } else {
                    manList.clear();
                    showManList();
                }

                if (model.getMaleList() != null && model.getMaleList().size() > 0) {//男厕
                    thirdList.clear();
                    thirdList.addAll(model.getFamilyList());
                    showThirdList();
                } else {
                    thirdList.clear();
                    showThirdList();
                }
                //右侧环境显隐
                if (!model.isMaleEnvEnable() && !model.isFemaleEnvEnable() && !model.isFamilyEnvEnable()) {
                    llEnvEnable.setVisibility(View.GONE);
                } else {
                    llEnvEnable.setVisibility(View.VISIBLE);
                }
                llMaleEnvEnable.setVisibility(model.isMaleEnvEnable() ? View.VISIBLE : View.GONE);
                llFemaleEnvEnable.setVisibility(model.isFemaleEnvEnable() ? View.VISIBLE : View.GONE);
                llFamilyEnvEnable.setVisibility(model.isFamilyEnvEnable() ? View.VISIBLE : View.GONE);


                Log.e("GlideUtil", "刷新");
                calculateHashForImageAsync(model.getLogoPath(), new ImageHashListener() {
                    @Override
                    public void onHashCalculated(String hash) {
                        // 比较哈希值，如果发生变化则刷新图片
                        if (!hash.equals(previousHash)) {
                            previousHash = hash; // 更新哈希值
                            getActivity().runOnUiThread(() -> {
                                // 图片内容发生变化，刷新图片
                                GlideUtil.loadImageWithoutCache(model.getLogoPath(), ivTitleLogo);
                            });
                        }
                    }

                    @Override
                    public void onError(String errorMessage) {
                        // 处理错误情况
                    }
                });


//                // 定义一个 Handler
//                Handler handler = new Handler(Looper.getMainLooper());
//
//                // 模拟20秒后更改图片地址
//                handler.postDelayed(() -> {
//                    // 在这里更改图片地址为新地址
//                    String newImageUrl = "https://img.alicdn.com/imgextra/i3/2204177871674/O1CN01N8L5cq1OEk0uAmksK_!!2204177871674.jpg";
//                    // 调用计算哈希值并加载图片的方法
//                    calculateHashForImageAsync(newImageUrl, new ImageHashListener() {
//                        @Override
//                        public void onHashCalculated(String hash) {
//                            // 比较哈希值，如果发生变化则刷新图片
//                            if (!hash.equals(previousHash)) {
//                                previousHash = hash; // 更新哈希值
//                                getActivity().runOnUiThread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        // 图片内容发生变化，刷新图片
//                                        GlideUtil.loadImageWithoutCache(newImageUrl, ivTitleLogo);
//                                    }
//                                });
//                            }
//                        }
//
//                        @Override
//                        public void onError(String errorMessage) {
//                            // 处理错误情况
//                        }
//                    });
//                }, 10000); // 10秒后执行

//                //不会刷新图片 、 图片地址不会发生改变
//                boolean isRefresh = !mImagePath.equals(model.getLogoPath());
//                if (isRefresh) {
//                    GlideUtil.loadImageWithoutCache(model.getLogoPath(), ivTitleLogo);
//                    mImagePath = model.getLogoPath();
//                }

                //抖动
//                Glide.get(requireActivity()).clearMemory();
//                Glide.with(requireActivity())
//                        .clear(ivTitleLogo);
//                Glide.with(requireActivity())
//                        .load(model.getLogoPath())
//                        .centerInside()
//                        .signature(new ObjectKey(System.currentTimeMillis()))
//                        .transition(DrawableTransitionOptions.withCrossFade())
//                        .diskCacheStrategy(DiskCacheStrategy.NONE)
//                        .into(ivTitleLogo);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private String mImagePath = "";

    public interface ImageHashListener {
        void onHashCalculated(String hash);

        void onError(String errorMessage);
    }

    private String previousHash = "";

    private void calculateHashForImageAsync(final String imageUrl, final ImageHashListener listener) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    MessageDigest digest = MessageDigest.getInstance("MD5");
                    URL url = new URL(imageUrl);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    connection.setDoInput(true);
                    connection.connect();

                    InputStream is = connection.getInputStream();
                    byte[] buffer = new byte[8192];
                    int read;

                    while ((read = is.read(buffer)) > 0) {
                        digest.update(buffer, 0, read);
                    }

                    byte[] hash = digest.digest();

                    // 将哈希值转换为十六进制字符串
                    StringBuilder hexString = new StringBuilder();
                    for (byte b : hash) {
                        String hex = Integer.toHexString(0xFF & b);
                        if (hex.length() == 1) {
                            hexString.append('0');
                        }
                        hexString.append(hex);
                    }

                    is.close();

                    final String hashResult = hexString.toString();

                    // 在主线程中通过回调返回结果
                    listener.onHashCalculated(hashResult);

                } catch (Exception e) {
                    e.printStackTrace();
                    listener.onError("Error occurred during hash calculation.");
                }
            }
        }).start();
    }

    @Override
    public void getCityAndKeyConfResult(CityConfModel model) {
        if (model != null) {
            cityConfModel = model;
            if (!TextUtils.isEmpty(model.getCityId()) && !TextUtils.isEmpty(model.getKey())) {
                getWeatherInfo();
            } else {
                getCityAndKeyConf();
            }
        }
    }


    @Override
    public void getSmartToiletNameConfResult(TitleModel model) {
//        if (model != null && !TextUtils.isEmpty(model.getLogoPath())) {
//            ivTitleLogo.setVisibility(View.VISIBLE);
//            Glide.with(mContext).load(model.getLogoPath()).into(ivTitleLogo);
//        } else {
//            ivTitleLogo.setVisibility(View.INVISIBLE);
//        }
    }


    @Override
    public void getSmartToiletInterfaceConfResult(SmartToiletInterfaceConfModel ztConfigurationModel) {
        if (ztConfigurationModel != null) {
            if (!TextUtils.isEmpty(ztConfigurationModel.getBgImage())) {
                //通过Glide获取网络图片宽高
                Glide.with(mContext).asBitmap().load(ztConfigurationModel.getBgImage()).into(new CustomTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
                        iv_bg_img.setImageBitmap(bitmap);
                        iv_bg_img2.setImageBitmap(bitmap);
                        int width = bitmap.getWidth();
                        int height = bitmap.getHeight();
                        if (ztConfigurationModel.getControls() != null && ztConfigurationModel.getControls().size() > 0) {
                            zt_show_tag_layout.setData(ztConfigurationModel, iv_bg_img.getWidth(), iv_bg_img.getHeight(), ztConfigurationModel.getWidth(), ztConfigurationModel.getHeight());
                        } else {
                            zt_show_tag_layout.setData(null, iv_bg_img.getWidth(), iv_bg_img.getHeight(), ztConfigurationModel.getWidth(), ztConfigurationModel.getHeight());
                        }
                        if (ztConfigurationModel.getControls() != null && ztConfigurationModel.getControls().size() > 0) {
                            zt_show_tag_layout2.setData(ztConfigurationModel, iv_bg_img2.getWidth(), iv_bg_img2.getHeight(), ztConfigurationModel.getWidth(), ztConfigurationModel.getHeight());
                        } else {
                            zt_show_tag_layout2.setData(null, iv_bg_img2.getWidth(), iv_bg_img2.getHeight(), ztConfigurationModel.getWidth(), ztConfigurationModel.getHeight());
                        }
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable drawable) {

                    }
                });
//                GlideUtil.loadImageWithCache(ztConfigurationModel.getBgImage(), R.drawable.ic_overtime, iv_bg_img, "unique_signature");
            }
        }
    }


    public AMapLocationClient mLocationClient = null;
    //声明定位回调监听器
    public AMapLocationClientOption mLocationOption = null;

//    /**
//     * 初始化定位
//     *
//     * @since 2.8.0
//     */
//    private void initLocation() {
//        //初始化client
//        try {
//            mLocationClient = new AMapLocationClient(mActivity.getApplicationContext());
//            mLocationOption = getDefaultOption();
//            //设置定位参数
//            mLocationClient.setLocationOption(mLocationOption);
//            // 设置定位监听
//            mLocationClient.setLocationListener(locationListener);
//            // 启动定位
//            mLocationClient.startLocation();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }

//    private void privacyCompliance() {
//        AMapLocationClient.updatePrivacyShow(mContext, true, true);
//        SpannableStringBuilder spannable = new SpannableStringBuilder("\"亲，为了更好的获取到天气信息，我们会获取您的位置，获取当前城市的信息，【您有权拒绝或取消授权】\t拒绝之后将无法获取到该城市的天气信息；\n");
//        spannable.setSpan(new ForegroundColorSpan(Color.BLACK), 35, 42, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        new AlertDialog.Builder(mActivity)
//                .setTitle("温馨提示(隐私合规示例)")
//                .setMessage(spannable)
//                .setPositiveButton("同意", (dialogInterface, i) -> {
//                    try {
//                        AMapLocationClient.updatePrivacyAgree(mContext, true);
//                        initLocation();
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                })
//                .setNegativeButton("不同意", (dialogInterface, i) -> AMapLocationClient.updatePrivacyAgree(mContext, false))
//                .show();
//    }

//    /**
//     * 默认的定位参数
//     *
//     * @author hongming.wang
//     * @since 2.8.0
//     */
//    private AMapLocationClientOption getDefaultOption() {
//        AMapLocationClientOption mOption = new AMapLocationClientOption();
//        try {
//            mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选，设置定位模式，可选的模式有高精度、仅设备、仅网络。默认为高精度模式
//            mOption.setGpsFirst(false);//可选，设置是否gps优先，只在高精度模式下有效。默认关闭
//            mOption.setHttpTimeOut(30000);//可选，设置网络请求超时时间。默认为30秒。在仅设备模式下无效
//            mOption.setInterval(2000);//可选，设置定位间隔。默认为2秒
//            mOption.setNeedAddress(true);//可选，设置是否返回逆地理地址信息。默认是true
//            mOption.setOnceLocation(true);//可选，设置是否单次定位。默认是false
//            mOption.setOnceLocationLatest(true);//可选，设置是否等待wifi刷新，默认为false.如果设置为true,会自动变为单次定位，持续定位时不要使用
//            AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选， 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
//            mOption.setSensorEnable(false);//可选，设置是否使用传感器。默认是false
//            mOption.setWifiScan(true); //可选，设置是否开启wifi扫描。默认为true，如果设置为false会同时停止主动刷新，停止以后完全依赖于系统刷新，定位位置可能存在误差
//            mOption.setLocationCacheEnable(true); //可选，设置是否使用缓存定位，默认为true
//            mOption.setGeoLanguage(AMapLocationClientOption.GeoLanguage.DEFAULT);//可选，设置逆地理信息的语言，默认值为默认语言（根据所在地区选择语言）
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return mOption;
//    }


//    /**
//     * 定位监听
//     */
//    AMapLocationListener locationListener = new AMapLocationListener() {
//        @Override
//        public void onLocationChanged(AMapLocation location) {
//            try {
//                if (null != location) {
//                    StringBuffer sb = new StringBuffer();
//                    //errCode等于0代表定位成功，其他的为定位失败，具体的可以参照官网定位错误码说明
//                    if (location.getErrorCode() == 0) {
//                        Common.CITY_NAME = location.getDistrict();
//                        SpMkvUtils.encode(Common.SP_CITY_KEY, location.getDistrict());
//                        getGeoCityLookup();
//                        sb.append("定位成功" + "\n");
//                        sb.append("定位类型: " + location.getLocationType() + "\n");
//                        sb.append("经    度    : " + location.getLongitude() + "\n");
//                        sb.append("纬    度    : " + location.getLatitude() + "\n");
//                        sb.append("精    度    : " + location.getAccuracy() + "米" + "\n");
//                        sb.append("提供者    : " + location.getProvider() + "\n");
//
//                        sb.append("速    度    : " + location.getSpeed() + "米/秒" + "\n");
//                        sb.append("角    度    : " + location.getBearing() + "\n");
//                        // 获取当前提供定位服务的卫星个数
//                        sb.append("星    数    : " + location.getSatellites() + "\n");
//                        sb.append("国    家    : " + location.getCountry() + "\n");
//                        sb.append("省            : " + location.getProvince() + "\n");
//                        sb.append("市            : " + location.getCity() + "\n");
//                        sb.append("城市编码 : " + location.getCityCode() + "\n");
//                        sb.append("区            : " + location.getDistrict() + "\n");
//                        sb.append("区域 码   : " + location.getAdCode() + "\n");
//                        sb.append("地    址    : " + location.getAddress() + "\n");
//                        sb.append("兴趣点    : " + location.getPoiName() + "\n");
//                        //定位完成的时间
//                        sb.append("定位时间: " + DateUtil.longToString(location.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n");
//                    } else {
//                        mLocationClient.startLocation();
//                        //定位失败
//                        sb.append("定位失败" + "\n");
//                        sb.append("错误码:" + location.getErrorCode() + "\n");
//                        sb.append("错误信息:" + location.getErrorInfo() + "\n");
//                        sb.append("错误描述:" + location.getLocationDetail() + "\n");
//                    }
//                    sb.append("***定位质量报告***").append("\n");
//                    sb.append("* WIFI开关：").append(location.getLocationQualityReport().isWifiAble() ? "开启" : "关闭").append("\n");
//                    sb.append("* GPS状态：").append(getGPSStatusString(location.getLocationQualityReport().getGPSStatus())).append("\n");
//                    sb.append("* GPS星数：").append(location.getLocationQualityReport().getGPSSatellites()).append("\n");
//                    sb.append("* 网络类型：" + location.getLocationQualityReport().getNetworkType()).append("\n");
//                    sb.append("* 网络耗时：" + location.getLocationQualityReport().getNetUseTime()).append("\n");
//                    sb.append("****************").append("\n");
//                    //定位之后的回调时间
//                    sb.append("回调时间: " + DateUtil.longToString(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n");
//
//                    //解析定位结果，
//                    String result = sb.toString();
//                    Log.e("解析定位结果", result);
//                } else {
//                    Log.e("local", "定位失败！");
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//    };
//
//    /**
//     * 获取GPS状态的字符串
//     *
//     * @param statusCode GPS状态码
//     * @return
//     */
//    private String getGPSStatusString(int statusCode) {
//        String str = "";
//        try {
//            switch (statusCode) {
//                case AMapLocationQualityReport.GPS_STATUS_OK:
//                    str = "GPS状态正常";
//                    break;
//                case AMapLocationQualityReport.GPS_STATUS_NOGPSPROVIDER:
//                    str = "手机中没有GPS Provider，无法进行GPS定位";
//                    break;
//                case AMapLocationQualityReport.GPS_STATUS_OFF:
//                    str = "GPS关闭，建议开启GPS，提高定位质量";
//                    break;
//                case AMapLocationQualityReport.GPS_STATUS_MODE_SAVING:
//                    str = "选择的定位模式中不包含GPS定位，建议选择包含GPS定位的模式，提高定位质量";
//                    break;
//                case AMapLocationQualityReport.GPS_STATUS_NOGPSPERMISSION:
//                    str = "没有GPS定位权限，建议开启gps定位权限";
//                    break;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return str;
//    }
}
